﻿using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyWrite.API.Appicant.Command.MenuCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyWrite.API.Controllers
{
    /// <summary>
    /// 菜单管理模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMediator mediator;

        public MenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<APIResult<string>> UpdateMenu([FromBody]MenuUpdateCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 批量删除菜单(逻辑删除)
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete]
        public async Task<APIResult<string>> DeleteMenu([FromQuery]DeleteMenuCommand request)
        {
            return await mediator.Send(request);
        }



        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<APIResult<string>> AddMenu([FromBody]AddMenuCommand request)
        { 
            return await mediator.Send(request);
        }


    }
}
